package view;

import java.awt.*;
import java.awt.event.*; 
import javax.swing.*;

public class ViewCalculator extends JFrame implements ActionListener {
	
	private static final long serialVersionUID = 1L;
	
	Container c1;
	JButton b1, b2, b3, b4, b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20, b21,b22, b23, b24, b25;	
    JTextField t1;
    JPanel p1,p2;
    JLabel l1;
	
public  ViewCalculator() {
		
	    c1=getContentPane(); 
    	
    	setLayout(new FlowLayout());
	    p1 = new JPanel(new GridLayout(5,4,2,2));
       	p2 = new JPanel(new BorderLayout());
        t1 = new JTextField(29);
    	
        l1=new JLabel(" SFT II. Grupo A. UNAL.");
        
          
        b1 = new JButton("1");
		b2 = new JButton("2");
		b3 = new JButton("3");
		b4 = new JButton("4");
		b5 = new JButton("5");
		b6 = new JButton("6");
		b7 = new JButton("7");
	    b8 = new JButton("8");
	    b9 = new JButton("9");
	    b10 = new JButton(".");
	    b11 = new JButton("0");
	    b12 = new JButton("+");
	    b13 = new JButton("-");
	    b14 = new JButton("=");
	    b15 = new JButton("*");
	    b16 = new JButton("/");
	    b17 = new JButton("CE");
	    b18 = new JButton("sin");
	    b19 = new JButton("cos");
	    b20 = new JButton("tan");
	    b21 = new JButton("exp");
	    b22 = new JButton("ln");
	    b23 = new JButton("x^n");
	    b24 = new JButton("sqrt");
	    b25 = new JButton("Ans");
	    
	   p2.add(t1,BorderLayout.NORTH);	 
       p2.add(l1,BorderLayout.SOUTH);
       p1.add(b18); //sin
  	   p1.add(b19); //cos 
       p1.add(b20); //tan 
       p1.add(b22); //ln 
       p1.add(b23);  //x^n
       p1.add(b7); //7
	   p1.add(b8); //8 
  	   p1.add(b9); //9
  	   p1.add(b21); //exp
  	   p1.add(b24); //sqrt
  	   p1.add(b4); //4
  	   p1.add(b5); //5
  	   p1.add(b6); //6
  	   p1.add(b15); //*
  	   p1.add(b16); ///
  	   p1.add(b1); //1
  	   p1.add(b2); //2
  	   p1.add(b3); //3
  	   p1.add(b12); //+
	   p1.add(b13); //-
  	   p1.add(b11); //0
  	   p1.add(b10); //.
  	   p1.add(b17); //CE
  	   p1.add(b25); //Ans
  	   p1.add(b14); //=
  	   
  	    c1.add(p2);
	    c1.add(p1);
	    setLocation(500,300);
	    setSize(500,500);
	    t1.setBackground(Color.pink );
	    t1.setEditable( false );
	    setVisible(true);
	    
		
  b1.addActionListener(this);
  b2.addActionListener(this);
  b3.addActionListener(this);
  b4.addActionListener(this);
  b5.addActionListener(this);
  b6.addActionListener(this);
  b7.addActionListener(this);
  b8.addActionListener(this);
  b9.addActionListener(this);
  b10.addActionListener(this);
  b11.addActionListener(this);
  b12.addActionListener(this); 
  b13.addActionListener(this);  	
  b14.addActionListener(this);  	
  b15.addActionListener(this);  	
  b16.addActionListener(this);  	
  b17.addActionListener(this);  	
  b18.addActionListener(this);   
  b19.addActionListener(this);  
  b20.addActionListener(this);  
  b21.addActionListener(this);  
  b22.addActionListener(this);
  b23.addActionListener(this);
  b24.addActionListener(this);  
  b25.addActionListener(this);  
  
    }	
    
          
    
    @Override
	public void actionPerformed(ActionEvent ae) {

		// double x = Double.parseDouble(t1.getText()); 
		 //double y = Double.parseDouble(t1.getText()); 
    	
		  //double opera =0.0, operador2=0.0;
		   	   
		   //if (ae.getSource()== b1) {t1.setText("" + opera); }
		  
		  // else if (ae.getSource()==b2){opera= x-y; t3.setText("" + opera); }
		  // else if (ae.getSource()==b3){opera= x*y; t3.setText("" + opera); }
		   //else if (ae.getSource()==b4){opera= x/y; t3.setText("" + opera); }	
		   //else if (ae.getSource()==b5){opera= Math.sqrt(x);t3.setText("" + opera); }   
		   //else if (ae.getSource()==b6){opera= Math.sqrt(y);t3.setText("" + opera); }      
		   //else if (ae.getSource()==b7){opera= Math.pow( x,y );t3.setText("" + opera); }   
		   //else if (ae.getSource()==b8){opera= Math.pow( y,x );t3.setText("" + opera); }
		   //else if (ae.getSource()==b9){opera= x%y ;t3.setText("" + opera); }
    	
    		
    	// TODO Auto-generated method stub
		
	}

}     
	
    